using Microsoft.EntityFrameworkCore;
using UniversalAdminSystem.Domian.Core.ValueObjects;
using UniversalAdminSystem.Domian.UserConversations.Aggregates;
using UniversalAdminSystem.Domian.UserConversations.IRepository;
using UniversalAdminSystem.Infrastructure.Persistence.DbContexts;

namespace UniversalAdminSystem.Infrastructure.Persistence.Repositories;

public class MessageRepository : BaseRepository<Message>, IMessageRepository
{
    public MessageRepository(UniversalAdminSystemDbContext dbContext) : base(dbContext)
    {
    }

    public async Task<IEnumerable<Message>> GetByConversationIdAsync(Guid conId)
    {
        var ConId = ConversationId.Create(conId);
        var list = await _TDs.Where(m => m.ConversationId == ConId).OrderBy(m=>m.CreateDate).AsNoTracking().ToListAsync();
        return list;
    }

    public async Task RemoveByConversationIdAsync(Guid conversationId)
    {
        var ConId = ConversationId.Create(conversationId);
        await _TDs.Where(m => m.ConversationId == ConId).ExecuteDeleteAsync();
    }
}

